(More) Recursive Type Aliases
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#more-recursive-type-aliases
typescriptでは再帰的な型定義ができなかった
interfaceを経由する回避策はあった
typescript 3.7からできるっぽい
かつて
code:ts
type Json =
| string
| number
| boolean
| null
| JsonObject
| JsonArray;
interface JsonObject {
property: string: Json;
}
interface JsonArray extends Array<Json> {}
これが3.7でこうかける
code:ts
type Json =
| string
| number
| boolean
| null
| { property: string: Json }
| Json[];
TypeScriptでのJSONの型
https://github.com/microsoft/TypeScript/pull/33050
以下なら循環参照ができるようになった
Instantiations of generic class and interface types (for example Array<Foo>).
Array types (for example Foo[]).
Tuple types (for example [string, Foo?]).
というか、typescriptでの再帰型定義のメモで調べて分かったが、再帰的な型定義というのは非常に難しい
たぶん停止性問題halting problemとかも関係していて
一般には、再帰を許すと型の定義が有限時間で終わるか分からん
めっちゃ再帰が続くとメモリ食いまくっていく
上記は、特定の場合にのみ、これを回避してもやっていけるという前提を元にやっている
また、typescriptの型まわりにおいて、特定の回避策的なものがあるが、
じゃあその回避策で無限ループしたり、メモリ食いまくったりするのかとかがよくわらかん
Haskell周辺は遅延評価とかそういうやつが関係している?